package com.Small;

  
  
 
import com.Welcome.R;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.LinearLayout;
import android.widget.TextView;
/** 
. *  
12. * @author GV 
13. * 
14. */  
public class ImageAdapter extends BaseAdapter {  
    private Context mContext;  
    
    private ImageView[] imgItems;
    
    private LinearLayout[] linearLayouts; 
    
    private int selResId;  
    
    public ImageAdapter(Context c,int[] picIds,int width,int height,int selResId) {   
        mContext = c;   
        this.selResId=selResId;
        linearLayouts=new LinearLayout[picIds.length]; 
        imgItems=new ImageView[picIds.length];  
        for(int i=0;i<picIds.length;i++)  
        {  	        DisplayMetrics dm = new DisplayMetrics();
        Activity activity = (Activity)mContext;
        activity.getWindowManager().getDefaultDisplay().getMetrics(dm); 
        
            imgItems[i] = new ImageView(mContext); 
            LinearLayout.LayoutParams glp = new LinearLayout.LayoutParams( Common.dip2px(50, dm), Common.dip2px(30, dm));
            LinearLayout.LayoutParams ly = new LinearLayout.LayoutParams(width, height);
            imgItems[i].setLayoutParams(glp); 
            glp.gravity = Gravity.CENTER;
            imgItems[i].setAdjustViewBounds(true);   
            //imgItems[i].setPadding(2, 2, 2, 2);   
            imgItems[i].setImageResource(picIds[i]); 
            imgItems[i].setScaleType(ScaleType.CENTER_INSIDE);
            linearLayouts[i] = new LinearLayout(mContext);
            linearLayouts[i].setOrientation(LinearLayout.VERTICAL);
            linearLayouts[i].addView(imgItems[i]);
            TextView tv = new TextView(mContext);

            tv.setLayoutParams(new GridView.LayoutParams(width, Common.dip2px(3, dm)));
            tv.setText("");
            //tv.setPadding(2, 2, 2, 2);
            tv.setGravity(Gravity.CENTER);
            tv.setBackgroundColor(Color.TRANSPARENT);
            linearLayouts[i].addView(tv);
        }  
    }   
   
    public int getCount() {   
        return imgItems.length;   
    }   
   
    public Object getItem(int position) {   
        return position;   
    }   
   
    public long getItemId(int position) {   
        return position;   
    }   
  


    public void SetFocus(int index)    
    {    
        for(int i=0;i<imgItems.length;i++)    
        {    
            if(i!=index)    
            {    imgItems[i].setImageResource(R.drawable.a);
                imgItems[i].setBackgroundResource(0); 
            }    
        }    
        imgItems[index].setBackgroundResource(selResId); 
        imgItems[index].setImageResource(R.drawable.a);
    }    
      
    public View getView(int position, View convertView, ViewGroup parent) {   
    	LinearLayout imageView;   
        if (convertView == null) {   
            imageView=linearLayouts[position];  
        } else {   
            imageView = (LinearLayout) convertView;   
        }   
        return imageView;   
    }   
}   
